export type FixedLengthArray<T, N extends number> = [T, ...T[]] & { length: N };
export class TypeUtils {
 
    static isRealNull(object: Object): boolean {
        return null == object;
    }
 
    static isAllNull(object: Object): boolean {
        return null == object || '' === object;
    }
 
    static isNumber(object: Object): boolean {
        return null != object && object.constructor === Number;
    }
 
    static isString(object: Object): boolean {
        return null != object && object.constructor === String;
    }
 
    static isBool(object: Object): boolean {
        return null != object && object.constructor === Boolean;
    }
 
    static isFunction(object: Object): boolean {
        return null != object && object.constructor === Function;
    }
 
    static isObj(object: Object): boolean {
        return null != object && object.constructor === Object;
    }
 
    static isMap(object: Object): boolean {
        return null != object && object.constructor === Map;
    }
 
    static isArray(object: Object): boolean {
        return null != object && object.constructor === Array;
    }
 
    static isNotEmptyArray(object: Object): boolean {
        return null != object && object.constructor === Array && object["length"] > 0;
    }
 
    static isEmptyArray(object: Object): boolean {
        return null != object && object.constructor === Array && 0 === object["length"];
    }
 
    static isType(object: Object, type: any): boolean {
        return null != object && object instanceof type;
    }
 
    static obj2Map(obj: any) {
        if (this.isMap(obj))
            return obj;
        let map = new Map();
        if ("{}" == obj || "" == obj)
            return map;
        this.isObj(obj) || (obj = JSON.parse(obj));
        for (let key of Object.keys(obj))
            map.set(key, obj[key]);
        return map;
    }
 
    static map2Obj(map: any) {
        if (this.isObj(map)) {
            return map;
        }
        let object = new Object();
        if (this.isMap(map))
            for (let key of map.keys())
                object[key] = map.get(key);
        return object;
    }
 
    static arr2Obj(arr: any) {
        if (this.isObj(arr))
            return arr;
        let object = new Object();
        if (this.isArray(arr))
            for (let i = 0; i < arr.length; i++)
                object[i] = arr[i];
        return object;
    }
 
}
 
